package demo;
class MyCircularQueue
{
    public int[] elem;

    public int front;

    public int rear;

    public int usesized ;
    public MyCircularQueue(int k) {
        elem = new int[k];
    }

    public Boolean enQueue(int value) {
        if(isFull())
        {
            return false;
        }
            elem[rear] = value;
            usesized++;
        if(usesized<elem.length)
            rear = (rear+1)%elem.length;
            return true;
    }


    public Boolean deQueue() {
        if(isEmpty())
        {
            return false;
        }
        rear = (rear==0)? 0:(rear-1)%elem.length;
        usesized--;
        return true;
    }

    public int Front() {

        if(isEmpty())
        {
            return -1;
        }
        return elem[front];
    }

    public int Rear() {
        if(isEmpty())
        {
            return -1;
        }
        return elem[rear];
    }

    public Boolean isEmpty() {
        return usesized == 0;
    }

    public Boolean isFull() {
        return usesized == elem.length;
    }
}

public class test {
    public static void main(String[] args) {
        MyCircularQueue q1 = new MyCircularQueue(3);
        System.out.print(q1.enQueue(1)+" ");
        System.out.print(q1.enQueue(2)+ " ");
        System.out.print(q1.enQueue(3)+" ");
        System.out.print(q1.enQueue(4)+" ");
        System.out.print(q1.Rear()+" ");
        System.out.print(q1.isFull()+" ");
        System.out.print(q1.deQueue()+" ");
        System.out.print(q1.enQueue(4)+" ");
        System.out.print(q1.Rear()+" ");


    }
}
